package com.core.guarantee.bo;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.core.guarantee.dao.GuaranteeDao;
import com.core.guarantee.dto.GuaranteeSearchCondition;
import com.core.guarantee.pojo.Guarantee;
import com.core.role.dao.RoleDao;
import com.core.role.pojo.Role;
import com.core.user.pojo.User;
import com.core.visaInfo.dao.VisaInfoDao;

@Service
public class GuaranteeBo {
	@Resource
	private GuaranteeDao guaranteeDao;
	@Resource
	private VisaInfoDao visaInfoDao;
	@Resource
	private RoleDao roleDao;
	public void add(GuaranteeSearchCondition sc) {
		visaInfoDao.addGuarantee(sc);
	}

	public Guarantee getById(GuaranteeSearchCondition sc) {
		
		return visaInfoDao.getGuaranteeById(sc);
	}

	public void update(GuaranteeSearchCondition sc) {
		visaInfoDao.updateGuarantee(sc);
		
	}

	public void del(Guarantee tempGuarantee) {
		visaInfoDao.delGuarantee(tempGuarantee);
	}

	public List<Guarantee> getPojoList(GuaranteeSearchCondition sc,User userInfo) {
		List<Role> roles =roleDao.searchPojoByUserId(userInfo);
		int isAdmin =0;
//		判断是否是管理员
		for (Role role : roles) {
			if (role.getId()==1) {
				isAdmin=1;
			}
		}
		if (isAdmin==1) {
			return visaInfoDao.getGuaranteePojoList(sc);

		}else{
			return visaInfoDao.getGuaranteePojoListByOperator(sc);
		}
	}
	public int getPojoListCnt(GuaranteeSearchCondition sc,User userInfo) {
		List<Role> roles =roleDao.searchPojoByUserId(userInfo);
		int isAdmin =0;
//		判断是否是管理员
		for (Role role : roles) {
			if (role.getId()==1) {
				isAdmin=1;
			}
		}
		if (isAdmin==1) {
			return visaInfoDao.getGuaranteePojoListCnt(sc);
		}else{
			return visaInfoDao.getGuaranteePojoListCntByOperator(sc);
		}
	}

	public void updateState(Guarantee tempGuarantee) {
		visaInfoDao.updateGuaranteeState(tempGuarantee);
	}
	public void updateReturnState(Guarantee tempGuarantee){
		visaInfoDao.updateReturnState(tempGuarantee);
	}

}
